/**
 * Created by LC on 2019/11/20
 */
package com.hw.paltfrom.service.mainscreen;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hw.paltfrom.mapper.HwCaseMainMapper;
import com.hw.paltfrom.pojo.HwCaseMain;
import com.hw.paltfrom.rescode.HWSystemCode;
import com.hw.paltfrom.utils.ResponeResultUtil;
import com.hw.paltfrom.vo.CityCaseMainStatisticVO;
import com.hw.paltfrom.vo.StationCaseMainStatisticVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class CaseMainStatisticService {

    @Autowired
    HwCaseMainMapper caseMainMapper;

    /**
     * 查询执法案件市级统计
     * @return
     */
    public Map<String,Object> queryCityStatistic(){
        //创建startTime
        Calendar cal=Calendar.getInstance();
        //当月
        cal.add(Calendar.MONTH,0);
        cal.set(Calendar.DAY_OF_MONTH,1);
        cal.set(Calendar.HOUR_OF_DAY,0);
        cal.set(Calendar.MINUTE,0);
        cal.set(Calendar.SECOND,0);
        Date startTime=cal.getTime();
        //创建wrapper
        Wrapper<HwCaseMain> caseMainWrapper = new EntityWrapper<>();
        caseMainWrapper.ne("F_AJ_CrtStep","01").between("F_AJ_CreateTime",startTime,new Date());
        //查询市级案件数量
        Integer cityCreatedCaseNum = caseMainMapper.selectCount(caseMainWrapper);
        //创建wrapper
        Wrapper<HwCaseMain> caseMainWrapper2 = new EntityWrapper<>();
        caseMainWrapper2.eq("F_AJ_CrtStep","07").between("F_AJ_EndTime",startTime,new Date());
        Integer cityFinishedCaseNum = caseMainMapper.selectCount(caseMainWrapper2);
        //创建返回的对象
        CityCaseMainStatisticVO cityCaseMainStatisticVO = new CityCaseMainStatisticVO();
        cityCaseMainStatisticVO.setCityCreatedCaseNum(cityCreatedCaseNum);
        cityCaseMainStatisticVO.setCityFinishedCaseNum(cityFinishedCaseNum);
        return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS, cityCaseMainStatisticVO);
    }

    /**
     * 查询执法案件超限站统计
     * @return
     */
    public Map<String,Object> queryStationStatistic(){
        //创建startTime
        Calendar cal=Calendar.getInstance();
        //当月
        cal.add(Calendar.MONTH,0);
        cal.set(Calendar.DAY_OF_MONTH,1);
        cal.set(Calendar.HOUR_OF_DAY,0);
        cal.set(Calendar.MINUTE,0);
        cal.set(Calendar.SECOND,0);
        Date d1=cal.getTime();
        String startTime = new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(d1);
        //今天
        String endTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

        List<StationCaseMainStatisticVO> stationCaseMainStatisticVOs = caseMainMapper.queryStationCase(startTime, endTime);
        return ResponeResultUtil.successNotice(HWSystemCode.SUCCESS,stationCaseMainStatisticVOs);
    }
}
